<?php
/**
 * Class C_OrderList 客户端 订单列表
 */
namespace V6;
class  C_OrderList extends \V5\C_OrderList
{
    public $isActive = true;
    public $remark = '获取客户端订单列表';

    public function get(array $req, array $post, &$result)
    {
        try {
            /* 授权验证【开始】 */
            if (!isset($req['uid'])) {
                return 'require user id ';
            }
            if (!isset($req['userType'])) {
                return 'require user type';
            }
            if (!isset($req['k']) || !isset($req['t'])) {
                return 'data error';
            }
            $customer_handler = new \Biz\UserHandler();
            $customer_cls = $customer_handler->getById($req['userType'], $req['uid']);
            if (!is_object($customer_cls) && $customer_cls->getEnterpriseId() == false) {
                return 'data error';
            }
            $enterprise_id = $customer_cls->getEnterpriseId();
            if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $enterprise_id, $req['t'], $req['k']) == false) {
                return 'data illegal';
            }
            /* 授权验证【结束】 */
            if (!array_key_exists('uid', $req) || empty($req['uid'])) {
                return 'require uid';//买家id
            }
            if (!array_key_exists('channelId', $req) || empty($req['channelId'])) {
                return 'require channelId';//渠道id
            }
            $l = isset($req['l']) ? $req['l'] : 100000;
            $o = isset($req['o']) ? $req['o'] : 0;
            // 实例化列表类
            $tabulation = new \Cls\Tabulation();
            // 初始化列表类相关参数
            if (array_key_exists('ordercode', $req) && !empty($req['ordercode'])) {
                $tabulation->setWhere('ordercode', $req['ordercode']);
            }
            $tabulation->setWhere('enterprise_customer_id', $req['uid'])
                ->setWhere('enterprise_channel_id', $req['channelId'])
                ->setWhere('enterprise_id', $enterprise_id)
                ->setWhere('status', '>', '0')
                ->setOffset($o)
                ->setLimit($l)
                ->setOrderBy('id', 'desc');
            $order_handler = new \Biz\OrderHandler();
            $order_handler->getOrderListByEnterpriseAndCustomerAndChannel($tabulation);
            $order_info = array();
            if ($tabulation->getSuccessStatus()) {
                foreach ($tabulation->getData() as $order_cls) {
                    $order_tmp = array();
                    $order_tmp['id'] = $order_cls->getId();
                    $order_tmp['ordercode'] = $order_cls->getCode();
                    $order_tmp['status'] = $order_cls->getStatus();
                    $order_tmp['contact'] = $order_cls->getContact();
                    $order_tmp['tel'] = $order_cls->getTelephone();
                    //展示 needpayprice
                    $order_tmp['price'] = $order_cls->getNeedPayPrice();
                    $order_tmp['pay_status'] = $order_cls->getPayStatus();
                    $order_tmp['insert_time'] = $order_cls->getInsertTime();
                    $order_tmp['is_pay_type'] = $order_cls->getIsPayType();
                    $order_tmp['pay_type_item_id'] = $order_cls->getPayTypeItemId();
                    $order_tmp['transaction_id'] = $order_cls->getTransactionId();
                    $order_tmp['status_string'] = $order_cls->getStatusStr();
                    $order_tmp['pay_status_string'] = $order_cls->getPayStatusStr();
                    $order_tmp['delivery_status_string'] = $order_cls->getDeliveryStatusStr();
                    $order_tmp['company'] = $order_cls->getEnterpriseCustomerInfo()->getCompany();
                    $action_list = array();
                    //未确认之前
                    if ($order_cls->getStatus() == \Cls\Order\Order::ORDER_STATUS_NEW) {
                        //已经支付
                        if ($order_cls->getPayStatus() == \Cls\Order\Order::PAY_STATUS_HAD) {
                            //线上
                            if ($order_cls->getIsPayType() == \Cls\Order\Order::IS_PAY_TYPE_ONLINE) {
                                $action_list[] = array('title' => "取消订单", "action" => "cancel");
                            }
                        } else {//未支付
                            //线上
                            if ($order_cls->getIsPayType() == \Cls\Order\Order::IS_PAY_TYPE_ONLINE) {
                                $action_list[] = array('title' => "立即支付", "action" => "promptlypay");
                                $action_list[] = array('title' => "取消订单", "action" => "cancel");
                            } else {//线下
                                $action_list[] = array('title' => "取消订单", "action" => "cancel");
                            }
                        }
                    } elseif ($order_cls->getStatus() == \Cls\Order\Order::ORDER_STATUS_GOODS_CONFIRMED) {
                        //已经支付
                        /*if ($order_cls->getPayStatus() == \Cls\Order\Order::PAY_STATUS_NOT) {
                            $action_list[] = array('title' => "立即支付", "action" => "promptlypay");
                        }*/

                    }
                    $order_tmp['actionList'] = $action_list;
                    $order_info['lists'][] = $order_tmp;
                }
            }
            $total = $tabulation->getTotal();
            $order_info['total'] = $total;
            $result = $order_info;
        } catch (Exception $e) {
            return $e->getMessage();
        }

    }

}

